package com.ye.simple

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.Toast
import com.ye.widget.StatusLayout
import com.ye.widget.status.BasicStatusLayout

class MainActivity : AppCompatActivity(), StatusLayout.OnRetryListener {
    private var mStatusLayout: StatusLayout? = null

    protected override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_status)
        setTitle("状态布局演示")
        mStatusLayout = findViewById<StatusLayout>(R.id.statusLayout)
        mStatusLayout!!.setOnRetryListener(this)
        findViewById<View>(R.id.btnEmpty).setOnClickListener(View.OnClickListener { mStatusLayout!!.showEmpty() })
        findViewById<View>(R.id.btnLoading).setOnClickListener(View.OnClickListener { mStatusLayout!!.showLoading() })
        findViewById<View>(R.id.btnLoadError).setOnClickListener(View.OnClickListener { mStatusLayout!!.showLoadError() })
        findViewById<View>(R.id.btnNetworkError).setOnClickListener(View.OnClickListener { mStatusLayout!!.showNetworkError() })
        findViewById<View>(R.id.btnContent).setOnClickListener(View.OnClickListener { mStatusLayout!!.showContent() })
        findViewById<View>(R.id.btnSettingLayout).setOnClickListener(View.OnClickListener {
            mStatusLayout!!.setNetworkError(object : BasicStatusLayout(this@MainActivity) {
                override fun getLayoutId(): Int {
                    return R.layout.view_layout_my_network
                }

                override fun getRetryId(): Int {
                    return R.id.btn_retry
                }
            })
        })

    }

    override fun onRetry() {
        Toast.makeText(this, "我点击了重试", Toast.LENGTH_LONG).show()
        mStatusLayout!!.showContent()
    }
}
